#include <REGX52.H>
#include "LCD1602.h"
#include "Timer0.h"

unsigned int Hours, minutes, seconds;

void main()
{
	LCD_Init();
	Timer0Init();
	LCD_ShowString(1,1,"time:");
	Hours=11;
	minutes=58;
	seconds=59;
	while(1)
	{
	  LCD_ShowNum(2,1,Hours,2);
		LCD_ShowChar(2,3,':');
		LCD_ShowNum(2,4,minutes,2);
		LCD_ShowChar(2,6,':');
		LCD_ShowNum(2,7,seconds,2);
	}
}	

void Timer0_Routine() interrupt 1
{
	static unsigned int t0;
	for(t0=0;t0<1000;t0++)
	{
		TL0 = 0x18;		//设置定时初值
		TH0 = 0xFC;		//设置定时初值
		while(!TF0);
		TF0=0;
	}
	seconds++;
	if(seconds==60) minutes++,seconds=0;
	if(minutes==60) Hours++,minutes=0;
	if(Hours==24) Hours=0;
}